<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>获取异常的原始类型</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="class.yar-server-exception.html">Yar_Server_Exception</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="class.yar-client-exception.html">Yar_Client_Exception</a></div>
 <div class="up"><a href="class.yar-server-exception.html">Yar_Server_Exception</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="yar-server-exception.gettype" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Yar_Server_Exception::getType</h1>
  <p class="verinfo">(PECL yar &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">Yar_Server_Exception::getType</span> &mdash; <span class="dc-title">获取异常的原始类型</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-yar-server-exception.gettype-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">string</span> <span class="methodname"><strong>Yar_Server_Exception::getType</strong></span>
    ( <span class="methodparam">void</span>
   )</div>

  <p class="para rdfs-comment">
   当服务端的服务函数抛出异常的时候,
   客户端本地会响应的抛出一个<a href="class.yar-server-exception.html" class="classname">Yar_Server_Exception</a>异常.
   有一个属性, 标明了服务端异常的类型. 这个方法就是获取这个异常类型.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-yar-server-exception.gettype-parameters">
  <h3 class="title">参数</h3>
  <p class="para">此函数没有参数。</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-yar-server-exception.gettype-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   string
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-yar-server-exception.gettype-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-5228">
   <p><strong>Example #1 <span class="function"><strong>Yar_Server_Exception::getType()</strong></span>示例</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
//Server.php<br /><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">Custom_Exception&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">Exception&nbsp;</span><span style="color: #007700">{};<br /><br />class&nbsp;</span><span style="color: #0000BB">API&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">throw_exception</span><span style="color: #007700">(</span><span style="color: #0000BB">$name</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;new&nbsp;</span><span style="color: #0000BB">Custom_Exception</span><span style="color: #007700">(</span><span style="color: #0000BB">$name</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">$service&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Yar_Server</span><span style="color: #007700">(new&nbsp;</span><span style="color: #0000BB">API</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">$service</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">handle</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;<br /></span><br />//Client.php<br /><span style="color: #0000BB">&lt;?php<br />$client&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Yar_Client</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://host/api.php"</span><span style="color: #007700">);<br /><br />try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">throw_exception</span><span style="color: #007700">(</span><span style="color: #DD0000">"client"</span><span style="color: #007700">);<br />}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">Yar_Server_Exception&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getType</span><span style="color: #007700">());<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getMessage</span><span style="color: #007700">());<br />}</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
string(16) &quot;Custom_Exception&quot;
string(6) &quot;client&quot;
</pre></div>
   </div>
  </div>
 </div>



 <div class="refsect1 seealso" id="refsect1-yar-server-exception.gettype-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"/>
  </ul>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="class.yar-server-exception.html">Yar_Server_Exception</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="class.yar-client-exception.html">Yar_Client_Exception</a></div>
 <div class="up"><a href="class.yar-server-exception.html">Yar_Server_Exception</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
